package com.ats.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.ats.dao.LeaverDao_ty;
import com.ats.model.Classe;
import com.ats.model.Leave;
import com.ats.util.JDBCUtil;
/**
 * 
 * @author TangRain
 *
 */
public class LeaveDaoImpl_ty implements LeaverDao_ty{

	@Override
	public boolean Student_leave(int sid, String lreson, String lnumber,String ldate,int iid) {
		boolean flag=false;
		StringBuffer  sql = new StringBuffer();
		sql.append(" INSERT INTO ats_leave (sid,lreson ,lnumber,ldate,iid)");
		sql.append(" VALUES (?,?,?,?,?)");
		Connection con =JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, sid);
			pst.setString(2, lreson);
			pst.setString(3, lnumber);
			pst.setString(4, ldate);
			pst.setInt(5, iid);
			int rs =pst.executeUpdate();
			if(rs>0){
				flag=true;
			}else {
				return false;
			}
			JDBCUtil.closeJDBC(pst, con);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}
	@Override
	public Classe Student_boolean(int sid) {
		Classe cla =new Classe();
		StringBuffer sql =new StringBuffer();
		sql.append(" select * from ats_classe");
		sql.append(" where sid=?");
		Connection con =JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, sid);
			ResultSet rs = pst.executeQuery();
			if(rs.next()){
				cla.setCid(rs.getInt("cid"));
				cla.setCname(rs.getString("cname"));
				cla.setIid(rs.getInt("tid"));
				cla.setSid(rs.getInt("sid"));
				cla.setIid(rs.getInt("iid"));
			}
			JDBCUtil.closeJDBC(pst, con);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return cla;
	}
}
